import { Component } from 'react'
import { View, Text } from '@tarojs/components'
import './index.scss'
import Taro from '@tarojs/taro'
import dayjs from 'dayjs'

interface IndexState {

}

export default class PrAgendaItem extends Component<any, IndexState>{
  constructor(props) {
    super(props)
    this.state = {

    }
  }

  componentWillMount() { }

  componentDidMount() { }

  componentWillUnmount() { }

  //render时的处理================
  getStyleTop(data, baseHeight) {
    if (!data) return ""
    let startTimeArr = data.startTime.split(":")
    let height1 = baseHeight * startTimeArr[0]
    let height2 = (startTimeArr[1] / 60) * baseHeight
    let top = Taro.pxTransform(height1 + height2)
    return top
  }
  getStyleHeight(data, baseHeight) {
    if (!data) return { height: "", ellipsis: false }
    let startTimeArr = data.startTime.split(":")
    let endTimeArr = data.endTime.split(":")
    let hourDiff = endTimeArr[0] - startTimeArr[0]
    let minuteDiff = endTimeArr[1] - startTimeArr[1]
    if (minuteDiff < 0) {
      hourDiff = hourDiff - 1
      minuteDiff = minuteDiff * -1
    }
    let height1 = hourDiff * baseHeight
    let height2 = (minuteDiff / 60) * baseHeight
    let height = height1 + height2
    let ellipsis = false//如果高度太小，就给最小高度并提示省略
    if (height < 16) {
      height = 16
      ellipsis = true
    }
    let Pxheight = Taro.pxTransform(height)
    return { height: Pxheight, ellipsis }
  }
  getStyleWidth(data, baseWidth,datalist) {
    if (!data) return { width: "" }
    let startArr = []
    let endArr = []
    datalist.map((item,index)=>{
      if(item.beAllDay =='1')return;
      startArr.push(item.startTime,item.endTime);
      endArr.push(item.endTime);
    })
    console.log(startArr,'itemitem',endArr);

    let startTimeArr = data.startTime.split(":")
    let endTimeArr = data.endTime.split(":")
    let arr = []
    arr.push(startTimeArr);
    let hourDiff = endTimeArr[0] - startTimeArr[0]
    let minuteDiff = endTimeArr[1] - startTimeArr[1]
    if (minuteDiff < 0) {
      hourDiff = hourDiff - 1
      minuteDiff = minuteDiff * -1
    }
    let width1 = baseWidth / hourDiff
    let width = width1
    console.log(startTimeArr, 'endTimeArr111', arr, datalist);

    return { width: width }
  }
  //=============================
  render() {
    // let text = this.props.text
    let data = this.props.data
    let datalist = this.props.datalist

    let baseHeight = 90
    let top = this.getStyleTop(data, baseHeight)
    let getHeight = this.getStyleHeight(data, baseHeight)
    let baseWidth = 100;
    let getWidth = this.getStyleWidth(data, baseWidth,datalist)
    console.log(getHeight, 'data1');
    return (
      <View className='agendaItem' style={{ top: top }}>
        <View className={`agendaItem_container ${getHeight.ellipsis ? "ellipsis" : ""}`} style={{ height: getHeight.height, width: getWidth.width + '%', }}>
          {
            getHeight.ellipsis ? "···" : data.scheduleTitle
          }
          {
            getHeight.ellipsis ? '' :
              <View className='agendaItem_address'>{data.scheduleLocation}</View>
          }
        </View>
      </View>
    )
  }
}